﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UFSSWebApp
{
    public partial class Login : System.Web.UI.Page
    {
        UFSSservicereference.UserCreds uc = new UFSSservicereference.UserCreds();
        UFSSservicereference.UFSSserviceSoapClient ussc = new UFSSservicereference.UFSSserviceSoapClient();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session.Count != 0)
                Response.Redirect("~/home.aspx");

            Session.Clear();
        }

        protected void Register_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/register.aspx");
        }
        
        protected void logLogin_Authenticate(object sender, AuthenticateEventArgs e)
        {
            uc.Username = logLogin.UserName.ToString();
            uc.Password = logLogin.Password.ToString();

            if (cbDisclaimer.Checked)
            {
                if (ussc.LoginUser(ref uc))
                {
                    Session.Add("usercreds", uc);
                    Session.Add("username", uc.Username);
                    Session.Timeout = 1440;
                    Response.Redirect("home.aspx");
                }
            }
            else
            {
                Response.Write("<SCRIPT LANGUAGE='Javascript'>alert(\"Please accept the disclaimer to continue\")</SCRIPT>");
            }
        }
    }
}